The present invention relates to implementing improved disk caching strategies in a computer. In particular, the present invention relates to a method for designating files as memory-resident, transient, or neither memory resident nor transient and appropriately caching the disk blocks associated with a designated file.
When operating, computers typically utilize three types of memory. Persistent memories that are not based on optical or magnetic media, e.g., EEPROM or Flash ROM, store the Basic Input/Output System (BIOS), boot parameters, and other startup routines. A volatile memory such as RAMBUS dynamic RAM (RDRAM) or synchronous dynamic RAM (SDRAM) stores data and programs presently in use, e.g., the operating system. A persistent memory typically using optical or magnetic media stores data and programs that are not presently in use.
The differences between the technologies implementing the different memory types offer advantages and disadvantages. Memories based on optical or magnetic media retain information in the absence of electrical power. Volatile memories like SDRAM require electrical power to retain information, but typically offer faster access times. Persistent ROM memories offer faster access times and retain information in the absence of electrical power, but have limited storage capacity and operate mostly as read-only devices.
Recognizing the different advantages offered by different memory types, operating system designers have developed various techniques to permit software applications to achieve fast access to data while maintaining copies of the data that will survive the removal of electrical power. One family of techniques is called xe2x80x9cdisk caching.xe2x80x9d Disk caching attempts to retain certain selected data in volatile memory while storing other data in a persistent storage device. Since volatile memory for caching is typically limited in size relative to the memory available in a persistent storage device, designers of disk caching algorithms must decide which data to cache and which data to store in slower, persistent memory.
Some prior art computer systems address this problem by implementing RAM disk functionality. Referring to FIG. 1, a typical prior art computer system 10 includes a microprocessor 12, a-memory 14, and an input/output (I/O) controller 16 connected by a system bus 18. The system bus 18 permits one or more of these interconnected components to communicate through the exchange of data. For example, the microprocessor 12 may send read or write requests to the memory 14 or the I/O controller 16.
The memory 14 in a prior art computer 10 itself typically includes three types of memory. RAM 20 stores data and programs presently in use. Programs can be a user application 36, an operating system 26, or a device driver such as a disk driver 28. ROM 22 stores the BIOS 30 and other boot routines. The mass storage device 32 provides a persistent memory typically using optical or magnetic media.
Performance-critical applications using large amounts of data, such as database systems, store data on mass storage device 32. However, mass storage device 32 typically has slower access times than RAM 20. Therefore, a performance-critical application should use as much RAM 20 storage as possible. Purchasing and installing a solid-state mass storage device (not shown) will also result in a performance gain, but these devices tend to be expensive and have access times inferior to RAM 20 storage.
Typically, a performance-critical application is designed and coded to use RAM 20 storage. However, an operating system 26 using a virtual memory system to redirect memory operations from RAM 20 to mass storage 32 will redirect the read and write transactions from the application, hindering its performance. A virtual memory system can be bypassed by using a RAM disk scheme, setting aside a portion of RAM 20 for use as a virtual disk volume. User applications 36 interact with the RAM disk 34 as if it were a disk volume on a mass storage device 32, but having significantly improved access times. Using a RAM disk scheme ensures that performance-critical applications access RAM 20 without undertaking special programming measures.
The RAM disk approach has drawbacks. For example, in some RAM disk implementations, disk blocks stored in the RAM disk 34 are duplicated in the disk cache 24. This unnecessary duplication wastes space in RAM 20 and potentially saturates cache 24, further hindering accesses to files in mass-storage 32. Moreover, RAM disks have volume-level granularity: all the files on the virtual volume must be stored in RAM disk 34. It is generally not possible to set the attributes of individual files to ensure they stay in RAM 20, while marking other files for storage in mass storage 32. Therefore, it is desirable to provide functionality to designate individual files to ensure that they are encached in RAM 20 or stored in mass storage 32.
The present invention relates to the problem of disk caching for improved access to data files. One object of the invention is to provide methods for caching disk blocks on a per-file basis. Another object of the invention is to permit individual users or software applications to designate files as memory-resident or transient. Yet another object of the invention is to provide a programmed computer that can cache disk blocks on a per-file basis.
In one aspect, the present invention is a method for improved access to data files. First, a portion of volatile memory is designated for use as a cache memory. After the cache is established, files are designated as memory-resident. Data blocks and index blocks associated with memory-resident files are maintained in the cache memory. In one embodiment, a file can be designated memory-resident while it is in use by a software application. In another embodiment, the memory-resident state of the file can be set by a user or by a software application. In yet another embodiment, maintaining blocks associated with memory-resident files in cache memory includes the steps of accessing a data block or an index block associated with a memory-resident file and storing the contents of the block in the cache memory. In one embodiment, the volatile memory for the cache is random-access memory (RAM). In another embodiment, the memory-resident cache is a sub-cache of a designated cache memory. In yet another embodiment, users or software applications can modify the size of the memory-resident cache. In one embodiment, it is possible to set a maximum size for the memory-resident cache, and disk blocks are removed from the cache when the maximum size is exceeded. In another embodiment, it is possible to designate a memory-resident file as not memory-resident, and data blocks and index blocks associated with the file are subsequently subject to default caching methods, making them more likely to be removed from cache memory when demand exceeds capacity.
In another aspect, the present invention is a method for improved access to data files. First, a portion of volatile memory is designated for use as a cache memory. After the cache is established, files are designated transient. Data blocks and index blocks corresponding to transient files are maintained in cache memory for a nominal duration. In one embodiment, blocks associated with transient files are not written to mass storage until the passage of the nominal period of time, whereupon they are written and subsequently removed from cache memory. In another embodiment, a file can be designated transient while being accessed by a software application. In yet another embodiment, a user or software application can designate a file as transient. In one embodiment, the volatile memory for the cache is random-access memory (RAM). In another embodiment, it is possible to designate a transient file as not transient, and data blocks and index blocks associated with the file are subsequently subject to default caching methods, making them less likely to be removed from cache memory when demand exceeds capacity.
In still another aspect, the present invention is a programmed computer with an improved caching system. The computer includes a non-volatile memory having a file. The file has at least one disk block and an attribute field corresponding to the state of the file as memory-resident or transient. The computer also includes a volatile memory having a cache containing disk blocks associated with memory-resident files. The volatile memory also has queue structures containing data structures that correspond to the data blocks stored in the cache. These data structures are only removed from the queue when required by size limits imposed on the cache. In one embodiment, the size limits imposed on the cache may be increased or decreased. In another embodiment, the disk block is an index block or a data block associated with the file. In another embodiment, the queue is a first queue composed of data structures corresponding to disk blocks associated with memory resident files, and a second queue composed of data structures corresponding to disk blocks associated with transient files.